package fragments;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.example.wangjin.menu.MainActivity;
import com.example.wangjin.menu.ProjectActivity;
import com.example.wangjin.menu.R;

/**
 * Created by wangjin on 15/5/27.
 */
public class ProjectFragment extends ListFragment {

    private String[] project_name = {"HCI项目","javaEE项目","系统结构论文"};
    private ListAdapter listAdapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d("new", "projectFragment");
        listAdapter = new ListAdapter(project_name);
        setListAdapter(listAdapter);
    }

    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        switch (position){
            case 0:
                Intent i = new Intent(getActivity(), ProjectActivity.class);
                startActivity(i);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.project_list,container,false);
        return v;
    }

    class ListAdapter extends ArrayAdapter<String>{

        public ListAdapter(String[] projectName){
            super(getActivity(),0,projectName);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            if(convertView == null) {
                convertView = getActivity().getLayoutInflater().inflate(R.layout.project_item, null);
                TextView t = (TextView) convertView.findViewById(R.id.project_name);
                t.setText(project_name[position]);

                return convertView;
            }else {
                return convertView;
            }

        }

    }



}
